package com.learn.xueer.ui.activity

import android.os.Bundle
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.LogUtils
import com.learn.xueer.app.base.BaseActivity
import com.learn.xueer.app.util.CacheUtil
import com.learn.xueer.databinding.ActivityStudySetBinding
import com.learn.xueer.ui.viewmodel.MineViewModel
import com.learn.xueer.ui.widgets.ScaleSeekBar
import kotlinx.android.synthetic.main.activity_study_set.bar
import kotlinx.android.synthetic.main.activity_study_set.bar_sound
import kotlinx.android.synthetic.main.activity_study_set.sw
import kotlinx.android.synthetic.main.activity_study_set.sw_rate


/**
 * 学习设置
 */
class StudySetActivity : BaseActivity<MineViewModel, ActivityStudySetBinding>() {

    var fontSizeScale = 1.0f
    var soundScale = 1.0f
    var fontSizeScaleList = arrayListOf<Float>(0.875f, 1.0f, 1.125f, 1.25f)
    var soundScaleList = arrayListOf<Float>(0.875f, 1.0f, 1.125f)
    override fun createObserver() {

        mDatabind.click = ProxyClick()

    }

    inner class ProxyClick {
        fun back() {
            finish()
        }

        fun submit() {

            CacheUtil.setFontSize(fontSizeScale)
            CacheUtil.setSound(soundScale)
            CacheUtil.setPlay(sw.isChecked)
            CacheUtil.setWithRead(sw_rate.isChecked)

            AppUtils.relaunchApp()

        }


    }

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.click = ProxyClick()
        var volume_sections = ArrayList<String>()
        volume_sections.add("偏小")
        volume_sections.add("标准")
        volume_sections.add("")
        volume_sections.add("超大")
        bar.initData(volume_sections)

        var volumeSound = ArrayList<String>()
        volumeSound.add("慢速 ")
        volumeSound.add("正常")
        volumeSound.add("快速")
        bar_sound.initData(volumeSound)

        fontSizeScale = CacheUtil.getFontSize()
        var indexOf = fontSizeScaleList.indexOf(fontSizeScale)
        LogUtils.e("$fontSizeScale $indexOf")

        bar.setFirstScaleValue(indexOf.toFloat())

        soundScale = CacheUtil.getSound()
        bar_sound.setFirstScaleValue(soundScaleList.indexOf(soundScale).toFloat())

        sw.isChecked = CacheUtil.getPlay()
        sw_rate.isChecked = CacheUtil.getWith()



        bar.setOnSeekChangeListener(object : ScaleSeekBar.OnSeekChangeListener {
            override fun onSeek(progress: Float) {
                LogUtils.e("progress:$progress")
                /**
                 * <!--字体大小 及倍数-->
                 *     <!--0.875=14/16 -->
                 *     <dimen name="sp_small">14sp</dimen>
                 *     <!--1  标准-->
                 *     <dimen name="sp_stander">16sp</dimen>
                 *     <!--1.125=18/16-->
                 *     <dimen name="sp_big1">18sp</dimen>
                 *     <!--1.25=20/16-->
                 *     <dimen name="sp_big2">20sp</dimen>
                 */
                fontSizeScale = fontSizeScaleList[progress.toInt()]

            }

            override fun OnSeekEnd(progress: Float) {

            }

        })
        bar_sound.setOnSeekChangeListener(object : ScaleSeekBar.OnSeekChangeListener {
            override fun onSeek(progress: Float) {
                LogUtils.e(progress)
                soundScale = soundScaleList[progress.toInt()]

            }

            override fun OnSeekEnd(progress: Float) {

            }

        })
    }


}